package com.rmc.verifycode;

import java.awt.*;

import static com.rmc.constanst.Constants.NEW_LINE;

public class MatchResult {

	public static final MatchResult NULL_RESULT =
			new MatchResult(new Point(Integer.MAX_VALUE, Integer.MAX_VALUE),
			                Double.MIN_VALUE,
			                new Char(new Dimension(0, 0), "?"));

	public final Point location;
	public final double matchFrequency;
	public final Char aChar;

	public MatchResult(Point location, double matchFrequency, Char aChar) {
		this.location = location;
		this.matchFrequency = matchFrequency;
		this.aChar = aChar;
	}

	@Override
	public String toString() {
		return "MatchResult [location=" + location + ", matchFrequency=" + matchFrequency
				+ "]"
				+ NEW_LINE + aChar;
	}

	public Rectangle getRectangle() {
		return new Rectangle(location, aChar.matrix.dim);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((aChar == null) ? 0 : aChar.hashCode());
		result = prime * result + ((location == null) ? 0 : location.hashCode());
		long temp = Double.doubleToLongBits(matchFrequency);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@SuppressWarnings({"RedundantIfStatement"})
	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (!(obj instanceof MatchResult)) return false;
		MatchResult other = (MatchResult) obj;
		if (aChar == null) {
			if (other.aChar != null) return false;
		} else if (!aChar.equals(other.aChar)) return false;
		if (location == null) {
			if (other.location != null) return false;
		} else if (!location.equals(other.location)) return false;
		if (Double.doubleToLongBits(matchFrequency) != Double
				.doubleToLongBits(other.matchFrequency)) return false;
		return true;
	}

}
